let arr= [1,2,[3,[4,5]]]

// console.log(arr.flat(Infinity))


function flatten2(arr) {
    let result = [];
    for(let item of arr) {
        if(Array.isArray(item)) {
            result.push(...flatten(item))
        } else {
            result.push(item)
        }
    }

    return result;

}

fun  

